<?php	/* gmslOpenSource 2008 */
/*
----------------------------------------------------------------------------------------
	Project name:		gmslappcore
	Section:		skin
----------------------------------------------------------------------------------------
	Script name:		browser_check.php
	Script location:	./gmslappcore/skin/
	Script version:		2.0
----------------------------------------------------------------------------------------
	Script info:		This page will determin which browser the user is using,
				which os they are using...
	Script dependencies:
 				~None.
----------------------------------------------------------------------------------------
	This script is part of the gmslappcore system which is released
	under the GNU licese.
	Copyright: (c) 2008 Andrew Cornford (groupmsl.co.uk)
	Email: projects@groupmsl.co.uk
	Website: www.groupmsl.co.uk?section=cms&page=view&t=gmslappcore&f=groupmsl Open Source/gmslappcore
----------------------------------------------------------------------------------------
	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
----------------------------------------------------------------------------------------
*/
// Please note, although this page is called browser_check.php, it can actually do alot more (detect OS...)

// Setting initial variable values.
$settings['browser_name']='Unknown';
$settings['browser_short_name']='Unknown';
$settings['browser_version']='Unknown';
$settings['platform']='Unknown';
$settings['user_agent']='Error in finding infomation';

// Assigning whole user agent string to variable.
$settings['user_agent']=$_SERVER['HTTP_USER_AGENT'];

// Trying to find a platform from the list.
if(eregi('win',$settings['user_agent'])) $settings['platform']='Windows';
elseif(eregi('mac',$settings['user_agent'])) $settings['platform']='Macintosh';
elseif(eregi('linux',$settings['user_agent'])) $settings['platform']='Linux';
elseif(eregi('OS/2',$settings['user_agent'])) $settings['platform']='OS/2';
elseif(eregi('BeOS',$settings['user_agent'])) $settings['platform']='BeOS';

// Testing for Opera
if(eregi('opera',$settings['user_agent']))
	{
	$temp['opera']=stristr($settings['user_agent'],'opera');
	if(eregi('/',$temp['opera']))
		{
		$temp['opera']=explode('/',$temp['opera']);
		$settings['browser_name']=$temp['opera'][0];
		$temp['opera']=explode(' ',$temp['opera'][1]);
		$settings['browser_version']=$temp['opera'][0];
		}
	else
		{
		$temp['opera']=explode(' ',stristr($temp['opera'],'opera'));
		$settings['browser_name']=$temp['opera'][0];
		$settings['browser_version']=$temp['opera'][1];
		}
	}

// Testing for WebTV.
elseif(eregi('webtv',$settings['user_agent']))
	{
	$temp['webtv']=explode('/',stristr($settings['user_agent'],'webtv'));
	$settings['browser_name']=$temp['webtv'][0];
	$settings['browser_version']=$temp['webtv'][1];
	}

// Testing for the first version of MSIE.
elseif(eregi('microsoft internet explorer',$settings['user_agent']))
	{
	$settings['browser_name']='Microsoft Internet Explorer';
	$settings['browser_version']='1.0';
	if(eregi('308|425|426|474|0b1',stristr($settings['user_agent'],'/'))) $settings['browser_version']='1.5';
	}

// Testing for any other version of MSIE.
elseif(eregi('msie',$settings['user_agent'])&&!eregi('opera',$settings['user_agent']))
	{
	$settings['browser_name']='Microsoft Internet Explorer';
	$temp['msie']=explode(' ',stristr($settings['user_agent'],'msie'));
	$settings['browser_version']=$temp['msie'][1];
	}

// Test for Pocket MSIE.
elseif(eregi('mspie',$settings['user_agent'])||eregi('pocket',$settings['user_agent']))
	{
	$temp['mspie']=explode(' ',stristr($settings['user_agent'],'mspie'));
	$settings['browser_name']='Microsoft Pocket Internet Explorer';
	$settings['platform']='Windows CE';
	if(eregi('mspie',$settings['user_agent'])) $settings['browser_version']=$temp['mspie'][1];
	else
		{
		$temp['mspie']=explode('/',$settings['user_agent']);
		$settings['browser_version']=$temp['mspie'][1];
		}
	}

// Test for Galeon.
elseif(eregi('galeon',$settings['user_agent']))
	{
	$temp['galeon']=explode(' ',stristr($settings['user_agent'],'galeon'));
	$temp['galeon']=explode('/',$temp['galeon'][0]);
	$settings['browser_name']=$temp['galeon'][0];
	$settings['browser_version']=$temp['galeon'][1];
	}

// Test for Konqueror.
elseif(eregi('Konqueror',$settings['user_agent']))
	{
	$test['konqueror']=explode(' ',stristr($settings['user_agent'],'Konqueror'));
	$test['konqueror']=explode('/',$test['konqueror'][0]);
	$settings['browser_name']=$test['konqueror'][0];
	$settings['browser_version']=$test['konqueror'][1];
	}

// Test for iCab.
elseif(eregi('icab',$settings['user_agent']))
	{
	$temp['icab']=explode(' ',stristr($settings['user_agent'],'icab'));
	$settings['browser_name']=$temp['icab'][0];
	$settings['browser_version']=$temp['icab'][1];
	}

// Test for OmniWeb.
elseif(eregi('omniweb',$settings['user_agent']))
	{
	$temp['omniweb']=explode('/',stristr($settings['user_agent'],'omniweb'));
	$settings['browser_name']=$temp['omniweb'][0];
	$settings['browser_version']=$temp['omniweb'][1];
	}

// Test for Phoenix.
elseif(eregi('Phoenix',$settings['user_agent']))
	{
	$settings['browser_name']='Phoenix';
	$temp['phoenix']=explode('/',stristr($settings['user_agent'],'Phoenix/'));
	$settings['browser_version']=$temp['phoenix'][1];
	}

// Test for Firebird.
elseif(eregi('firebird',$settings['user_agent']))
	{
	$settings['browser_name']='Firebird';
	$test['firebird']=stristr($settings['user_agent'],'Firebird');
	$test['firebird']=explode('/',$test['firebird']);
	$settings['browser_name']=$test['firebird'][1];
	}

// Test for Firefox.
elseif(eregi('Firefox',$settings['user_agent']))
	{
	$settings['browser_name']='Firefox';
	$temp['firefox']=stristr($settings['user_agent'],'Firefox');
	$temp['firefox']=explode('/',$temp['firefox']);
	$settings['browser_version']=$temp['firefox'][1];
	}

// Test for Mozilla Alpha/Beta versions.
elseif(eregi('mozilla',$settings['user_agent'])&&eregi('rv:[0-9].[0-9][a-b]',$settings['user_agent'])&&!eregi('netscape',$settings['user_agent']))
	{
	$settings['browser_name']='Mozilla';
	$temp['mozilla_ab']=explode(' ',stristr($settings['user_agent'],'rv:'));
	eregi('rv:[0-9].[0-9][a-b]',$settings['user_agent'],$temp['mozilla_ab']);
	$settings['browser_version']=str_replace('rv:','',$temp['mozilla_ab'][0]);
	}

// Test for Mozilla Stable versions.
elseif(eregi('mozilla',$settings['user_agent'])&&eregi('rv:[0-9]\.[0-9]',$settings['user_agent'])&&!eregi('netscape',$settings['user_agent']))
	{
	$settings['browser_name']='Mozilla';
	$temp['mozilla_s']=explode(' ',stristr($settings['user_agent'],'rv:'));
	eregi('rv:[0-9]\.[0-9]\.[0-9]',$settings['user_agent'],$temp['mozilla_s']);
	$settings['browser_version']=str_replace('rv:','',$temp['mozilla_s'][0]);
	}

// Test for Lynx and Amaya.
elseif(eregi('libwww',$settings['user_agent']))
	{
	if (eregi('amaya',$settings['user_agent']))
		{
		$temp['lynx_amaya']=explode('/',stristr($settings['user_agent'],'amaya'));
		$settings['browser_name']='Amaya';
		$temp['lynx_amaya']=explode(' ',$temp['lynx_amaya'][1]);
		$settings['browser_version']=$temp['lynx_amaya'][0];
		}
	else
		{
		$temp['lynx_amaya']=explode('/',$settings['user_agent']);
		$settings['browser_name']='Lynx';
		$settings['browser_version']=$temp['lynx_amaya'][1];
		}
	}

// Test for iPhone Safari.
elseif(eregi('iPhone',$settings['user_agent']))
	{
	$settings['browser_name']='Safari Mobile';
	$temp['safari']=stristr('Safari/',$settings['user_agent']);
	$temp['safari']=explode('/',$settings['user_agent']);
	$settings['browser_version']=$temp['safari'][1];
	}

// Test for Safari.
elseif(eregi('safari',$settings['user_agent']))
	{
	$settings['browser_name']='Safari';
	$temp['safari']=stristr('Safari/',$settings['user_agent']);
	$temp['safari']=explode('/',$settings['user_agent']);
	$settings['browser_version']=$temp['safari'][1];
	}

// Test for Netscape.
elseif(eregi('netscape',$settings['user_agent']))
	{
	$temp['netscape']=explode(' ',stristr($settings['user_agent'],'netscape'));
	$temp['netscape']=explode('/',$temp['netscape'][0]);
	$settings['browser_name']=$temp['netscape'][0];
	$settings['browser_version']=$temp['netscape'][1];
	}
elseif(eregi('mozilla',$settings['user_agent'])&&!eregi('rv:[0-9]\.[0-9]\.[0-9]',$settings['user_agent']))
	{
	$temp['netscape']=explode(' ',stristr($settings['user_agent'],'mozilla'));
	$temp['netscape']=explode('/',$temp['netscape'][0]);
	$settings['browser_name']='Netscape';
	$settings['browser_version']=$temp['netscape'][1];
	}

// Creating shorthand names for browsers.
if($settings['browser_name']=='Opera') $settings['browser_short_name']='OP';
elseif($settings['browser_name']=='WebTV') $settings['browser_short_name']='WTV';
elseif($settings['browser_name']=='Microsoft Internet Explorer') $settings['browser_short_name']='MSIE';
elseif($settings['browser_name']=='Microsoft Pocket Internet Explorer') $settings['browser_short_name']='MSPIE';
elseif($settings['browser_name']=='Galeon') $settings['browser_short_name']='GLN';
elseif($settings['browser_name']=='Konqueror') $settings['browser_short_name']='KONQ';
elseif($settings['browser_name']=='iCab') $settings['browser_short_name']='ICAB';
elseif($settings['browser_name']=='OmniWeb') $settings['browser_short_name']='ONIW';
elseif($settings['browser_name']=='Phoenix') $settings['browser_short_name']='PHNX';
elseif($settings['browser_name']=='Firebird') $settings['browser_short_name']='FRBD';
elseif($settings['browser_name']=='Firefox') $settings['browser_short_name']='FF';
elseif($settings['browser_name']=='Mozilla') $settings['browser_short_name']='MOZ';
elseif($settings['browser_name']=='Amaya') $settings['browser_short_name']='AMYA';
elseif($settings['browser_name']=='Lynx') $settings['browser_short_name']='LYNX';
elseif($settings['browser_name']=='Safari Mobile') $settings['browser_short_name']='SFRIM';
elseif($settings['browser_name']=='Safari') $settings['browser_short_name']='SFRI';
elseif($settings['browser_name']=='Netscape') $settings['browser_short_name']='NTSP';

// Clean up the name if it is necessary.
$settings['browser_name']=ereg_replace('[^a-z,A-Z]','',$settings['browser_name']);

// Clean up the version if necessary.       
$settings['browser_version']=ereg_replace('[^0-9,.,a-z,A-Z]','',$settings['browser_version']);
        
// Test for AOL.
if(eregi('AOL', $settings['user_agent']))
	{
	$temp['aol']=stristr($settings['user_agent'],'AOL');
	$temp['aol']=explode(' ',$temp['aol']);
	$bd['aol']=ereg_replace('[^0-9,.,a-z,A-Z]','',$temp['aol'][1]);
	}
?>
